<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>付款编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=income_engin','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=income_engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项类型</label>
                        <div class="layui-input-block">
                            <select id="budid" name="budid" lay-filter="budid"></select>
                            <p class="error" id="budid_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项摘要</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhai" id="zhai" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>付款依据</label>
                        <div class="layui-input-block">
                            <select id="yiju" name="yiju" lay-filter="yiju"></select>
                            <p class="error" id="yiju_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="yijuDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>依据(名称)</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="yijuid" class="layui-input yijuid">
                            <div class="choose_div" id="yijuid" key="1"></div>
                            <span class="choose_one" id="yijuDivClick" key="concaistuff"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">依据(供应方)</label>
                        <div class="layui-input-block">
                            <input type="text" id="yijuid_gonger" placeholder="请输入" readonly autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>请款金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" placeholder="请输入" autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>发票情况</label>
                        <div class="layui-input-block">
                            <div id="incqing"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>支付方式</label>
                        <div class="layui-input-block">
                            <div id="incdaotype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>付款对象</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="gonger" class="layui-input gonger">
                            <div class="choose_div" id="gonger" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=gonger&page=payment_engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">账户账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="banknum" id="banknum" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开户行</label>
                        <div class="layui-input-block">
                            <input type="text" name="bankname" id="bankname" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联单据</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="advanersDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="nexterDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="nexter"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    $("#commentForm").validate({
        rules: {
            zhai: {required: true},
            money: {required: true},
        },
        messages:{
            zhai: {required: "请输入"},
            money: {required: "请输入"},
        }
    });


    $("#yijuDivClick").click(function () {
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择项目名称");return false;
        }
        var key = $(this).attr('key');

        if(key == 'concaistuff'){
            openPage('../public/choose_contract_cai.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'stuffcai'){
            openPage('../public/choose_stuff_cai_pagepayment.php?dom=yijuid&enginid='+enginid+'&page=payment_engin','80%','80%')
        }else  if(key == 'stuffru'){
            openPage('../public/choose_stuff_ru.php?dom=yijuid&enginid='+enginid+'&page=payment_engin','80%','80%')
        }else  if(key == 'stuffjie'){
            openPage('../public/choose_stuff_jie.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'concailabour'){
            openPage('../public/choose_contract_cai.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=2','80%','80%')
        }else  if(key == 'labourshen'){
            openPage('../public/choose_labour_shen.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'labourjie'){
            openPage('../public/choose_labour_jie.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'labourling'){
            openPage('../public/choose_labour_ling.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'labouryong'){
            openPage('../public/choose_labour_yong.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'concaidevice'){
            openPage('../public/choose_contract_cai.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=3','80%','80%')
        }else  if(key == 'devicejie'){
            openPage('../public/choose_device_jie.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'devicelin'){
            openPage('../public/choose_device_lin.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'concaisubbao'){
            openPage('../public/choose_contract_cai.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=4','80%','80%')
        }else  if(key == 'subbaoshen'){
            openPage('../public/choose_subbao_shen.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'subbaojie'){
            openPage('../public/choose_subbao_jie.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=1','80%','80%')
        }else  if(key == 'concaiqi'){
            openPage('../public/choose_contract_cai.php?dom=yijuid&enginid='+enginid+'&page=payment_engin&caihetype=5','80%','80%')
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_add_payment_engin}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#flowsetname").text(data.flowsetname);
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                $("#number").val(data.number);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                }
                var budid_str = '<option value="">请选择</option>';
                var budid = res.data.budid;
                for (var key in budid){
                    budid_str += '<option value="'+key+'">'+budid[key]+'</option>';
                }
                $("#budid").html(budid_str);
                set_upd_yiju();

                xmselect_dan('incqing', res.data.incqing, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#incqing").find('xm-select').removeClass('error');
                    }else{
                        $("#incqing").find('xm-select').addClass('error');
                    }
                });
                xmselect_dan('incdaotype', res.data.incdaotype, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#incdaotype").find('xm-select').removeClass('error');
                    }else{
                        $("#incdaotype").find('xm-select').addClass('error');
                    }
                });

                initParseMoney();
                public_upload_file_load('upload_files');
                render_from();
                initParseMoney();
            }
        });

        form.on('select(budid)', function(data){

            if(data.value == ''){
                $('#budid_error').show().text('请选择');
                $('#budid_error').parent().find('input').addClass('select_error');
            }else{
                $('#budid_error').hide();
                $('#budid_error').parent().find('input').removeClass('select_error');
            }

            set_upd_yiju(data.value)
            reset_datas(1);
        });

        form.on('select(yiju)', function(data){
            if(data.value != 'none'){
                $("#yijuDiv").removeClass('layui-hide');
                $("#yijuDivClick").attr('key', data.value);
            }else{
                $("#yijuDiv").addClass('layui-hide');
                $("#yijuDivClick").attr('key', data.value);
            }
            $("#yijuid").html('');
            reset_datas(0);
        });


        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');

            data.field.yijuid = get_choose_val('yijuid');
            data.field.enginid = get_choose_val('enginid');
            data.field.gonger = get_choose_val('gonger');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();

                formValid('enginid');
                if(data.field.enginid == undefined || !data.field.enginid){
                    validRes = false;
                }


                if(data.field.budid == ''){
                    $('#budid_error').show().text('请选择');
                    $('#budid_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#budid_error').hide();
                    $('#budid_error').parent().find('input').removeClass('select_error');
                }

                if(data.field.yiju != 'none'){
                    formValid('yijuid');
                    if(data.field.yijuid == undefined || !data.field.yijuid){
                        validRes = false;
                    }
                }

                if(!data.field.incqing){
                    $("#incqing").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#incqing").find('xm-select').removeClass('error');
                }
                if(!data.field.incdaotype){
                    $("#incdaotype").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#incdaotype").find('xm-select').removeClass('error');
                }

                formValid('gonger');
                if(data.field.gonger == undefined || !data.field.gonger){
                    validRes = false;
                }

                if(!validRes){return false;}
            }


            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            public_flow_submit(data.field, ask_flowdata_add_payment_engin, ask_flowdata_edit_payment_engin, $(this).attr('but'));
            return false;
        });

    });



    function set_upd_yiju(budid) {
        var arr = {none:'无'};
        if(budid == 1){
            arr = {concaistuff:'材料合同', stuffcai:'材料采购单', stuffru:'入库单', stuffjie:'材料结算单',none:'无'};
        }else if(budid == 2){
            arr = {concailabour:'劳务合同', labourshen:'劳务进度款申报', labourjie:'完工结算单', labourling:'零星劳务单', labouryong:'用工单',none:'无'};
        }else if(budid == 3){
            arr = {concaidevice:'租赁合同', devicejie:'租赁结算', devicelin:'临时机械费登记', none:'无'};
        }else if(budid == 4){
            arr = {concaisubbao:'分包合同', subbaoshen:'分包进度款申报', subbaojie:'分包完工结算', none:'无'};
        }else if(budid == 5){
            arr = {concaiqi:'其他采购合同', none:'无'};
        }

        var yiju_str = '';
        for (var key in arr){
            yiju_str += '<option value="'+key+'">'+arr[key]+'</option>';
        }
        $("#yiju").html(yiju_str);
        render_from();

        var yiju = $("#yiju").val();
        if(yiju != 'none'){
            $("#yijuDiv").removeClass('layui-hide');
            $("#yijuDivClick").attr('key', yiju);
        }else{
            $("#yijuDiv").addClass('layui-hide');
            $("#yijuDivClick").attr('key', yiju);
        }
        $("#yijuid").html('');
    }



    function reset_datas(type=0) {
        $("#zhai").val('');
        if(type > 0){
            $("#yijuid").html('');
        }
        $("#yijuid_gonger").val('');
        $("#money").val('');
        $("#incqing .label-content").html('');
        $("#incdaotype .label-content").html('');
        $("#gonger").html('');
        $("#banknum").val('');
        $("#bankname").val('');
        $("#explain").val('');
    }




    function choose_enginid_delete() {
        reset_datas(1);
    }

</script>
</body>
</html>
